/**
 * 
 */
package org.statewalker.core.server;

import java.util.HashMap;
import java.util.Map;

/**
 * This class provides type-safe access to values stored in a {@link Map}.
 * <p>
 * Example of usage:
 * 
 * <pre>
 *  interface IMyFields {
 *      String getName();
 *      void setName(String name);
 *      int getAge();
 *      void setAge(int age);
 *  }
 *  ... 
 *  Accessor accessor = new Accessor();
 *  IMyFields fields = accessor.getAccessor(IMyFields.class);
 *  fields.setAge(38);
 *  fields.setName("John Smith");
 *  assertEquals(38, fields.getAge());
 *  assertEquals("John Smith", fields.getName());
 * </pre>
 * 
 * @author kotelnikov
 */
public class Accessor extends AbstractAccessor {

    private Map<String, Object> fMap = new HashMap<String, Object>();

    public Map<String, Object> getMap() {
        return new HashMap<String, Object>(fMap);
    }

    @Override
    protected Object getValue(String key) {
        return fMap.get(key);
    }

    public void setMap(Map<String, Object> values) {
        fMap = new HashMap<String, Object>(values);
    }

    @Override
    protected void setValue(String key, Object value) {
        fMap.put(key, value);
    }
}